package com.xiaomo.gitee.datamanager.util;

import com.xiaomo.gitee.datamanager.mapper.ImagesMapper;
import gnu.trove.map.TObjectLongMap;
import gnu.trove.map.hash.TObjectLongHashMap;
import jakarta.annotation.PostConstruct;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class ImagesSequenceUtils {

    public TObjectLongMap<String> sequenceMap = new TObjectLongHashMap<>();

    private final ImagesMapper imagesMapper;

    @Autowired
    public ImagesSequenceUtils(ImagesMapper imagesMapper) {
        this.imagesMapper = imagesMapper;
    }

    @PostConstruct
    public void loadImagesSequence() {
        sequenceMap.clear();
        imagesMapper.selectImagesWithRowNumberWithoutPager("name").forEach(image -> sequenceMap.put(image.getId(),image.getSequenceNumber()));
    }

}
